package com.itmuch.cloud.service;

import com.itmuch.cloud.entity.User;
import feign.hystrix.FallbackFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

/**
 * @author Aaron
 * @since 2020/12/25 16:46
 * <p>描述：</p>
 */
@Component
public class FeignClientFallbackFactory implements FallbackFactory<UserFeignClient> {
    public static final Logger LOGGER = LoggerFactory.getLogger(FeignClientFallbackFactory.class);

    @Override
    public UserFeignClient create(Throwable throwable) {
        return id -> {
            // 日志最好放在各个 fallback 方法中，而不要直接放在 create 方法中。
            // 否则在引用启动时就会打印日志
            LOGGER.info("fallback; reason was:{}", throwable);
            User user = new User();
            user.setId(-1L);
            user.setUsername("默认用户");
            return user;
        };
    }



}
